from django_filters import filters
from rest_framework.filters import BaseFilterBackend
from django_filters.filterset import FilterSet


# 自定义过滤规则
# class MyFilter(BaseFilterBackend):
#     def filter_queryset(self, request, queryset, view):
#         # 写过滤规则
#         # params = request.query_params().get('teacher')
#         params = request.GET('teacher')
#         # queryset.filter("")
#         return queryset[:1]
from course import models


# 扩展过滤
class CourseFilterSet(FilterSet):
    # 支持更多字段
    min_price = filters.NumberFilter(field_name='price', lookup_expr='gte')
    max_price = filters.NumberFilter(field_name='price', lookup_expr='lte')

    class Meta:
        model = models.Course
        fields = ['course_category']
